<?php
include_once "func.php";
//include_once "func_sms.php";

ini_set('display_errors', '0');
//error_reporting(0);//禁用错误报告 

// data:{ englishname:englishname,chinesename:chinesename,
// nationality:nationality,contactnumber:contactnumber,email:email,place:place},

//获取wx_openid
$wx_openid = $_POST['wx_openid'];
 if(!$wx_openid){
	$return = array(
	    'result' => 7
	);
	ajax_return($return);
}
//从member表中获取手机号

$sql = "select * from member where wx_openid='$wx_openid'";
$member = $db->get_row($sql);
$phonenumber = '';
$member_id = '';
if($member){
	$phonenumber = $member->phonenumber;
	$member_id = $member->id;
}


$fullname = $_POST['fullname'];
$qqnumber = $_POST['qqnumber'];
$sex = $_POST['sex'];
$height = $_POST['height'];
$weight = $_POST['weight'];
$birthday = $_POST['birthday'];
$thumb = $_POST['thumb'];
$description = $_POST['selfintro'];

// $sporttypes = $_POST['sporttypes'];
// $sporttitle = $_POST['sporttitle'];
// $orthertype = $_POST['orthertype'];
// $invitecode_f = $_POST['invitecode_f'];

 
if($fullname==''){
	$return = array(
	    'result' => 3
	);
	ajax_return($return);
}
 

// $sql = "insert into coach(fullname,height,weight,birthday,phonenumber,qqnumber,sex,sporttypes,sporttitle,orthertype,createdate,smscode,invitecode,invitecode_f) 
// values('$fullname','$height','$weight','$birthday','$phonenumber','$qqnumber','$sex','$sporttypes','$sporttitle','$orthertype',NOW(),'$smscode','$invitecode','$invitecode_f')";
// $res = $db->query($sql);

$sql = "select * from coach where member_id=$member_id";
$checksql = $db->get_row($sql);

if($checksql){
	$reviewcode = $checksql->review;
	$reviewarr = explode('|',$reviewcode);
	$reviewarr[0] = '1';
	$reviewcode = implode('|',$reviewarr);

    $sql = "update coach set fullname='$fullname',height='$height',weight='$weight',birthday='$birthday',qqnumber='$qqnumber',sex='$sex',thumb='$thumb',description='$description',review='$reviewcode' where member_id=$member_id";
    $db->query($sql);
}else{
	$sql = "insert into coach(fullname,height,weight,birthday,phonenumber,qqnumber,sex,createdate,member_id,thumb,description) 
	values('$fullname','$height','$weight','$birthday','$phonenumber','$qqnumber','$sex',NOW(),$member_id,'$thumb','$description')";
	$res = $db->query($sql);
}
 
  	$return = array(
	    'result' => 1
	);
	ajax_return($return);
   
?>